from datetime import datetime

from common.json_util import to_dict
from daos.album_record_info_dao import *
from rules import db_commit


def search_album_record_info(pk):
    result = to_dict(query_album_record_info(pk))
    return result

def search_album_record_info_by_album_info_id(pk):
    result = to_dict(query_album_record_info_by_album_info_id(pk))
    return result


def create_album_record_info(album_record_info_dict, is_commit=False):
    album_record_info_orm = AlbumRecordInfo()
    album_record_info_orm.album_info_id = album_record_info_dict.get('album_info_id')
    album_record_info_orm.license_num = album_record_info_dict.get('license_num')
    album_record_info_orm.registration_num = album_record_info_dict.get('registration_num')
    album_record_info_orm.ordinary_record_num = album_record_info_dict.get('ordinary_record_num')
    album_record_info_orm.key_record_num = album_record_info_dict.get('key_record_num')

    album_record_info_orm = add_album_record_info(album_record_info_orm, is_commit)

    if not is_commit:
        db_commit()

    return album_record_info_orm.to_dict()
